#include <iostream>

#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <GL/glu.h>

#include "glwrapper.hpp"
#include "window.hpp"
#include "events.hpp"
#include "cursor.hpp"
#include "shader.hpp"

int defaultWidth = 640, defaultHeight = 480;

int main(int argc, char** argv) {
    if (int result = carbon::C_GLWrappper::initialize() != 0) return result;
    if (int result = carbon::C_Window::initialize(defaultWidth, defaultHeight, "Carbon Engine", false) != 0) return result;
    carbon::C_Events::initialize();

    carbon::C_Shader* main_shader = carbon::C_Shader::load("res/shaders/main_vertex.glslv", "res/shaders/main_fragment.glslf");

    if (!carbon::C_GLWrappper::getShaderStatus(main_shader)) {
        std::cerr << "error: shader program does not exist" << std::endl;

        carbon::C_Window::terminate();
        carbon::C_GLWrappper::terminate();

        return 1;
    }

    carbon::C_GLWrappper::setBufferSwapInterval(1);
    while (carbon::C_Window::isOpen()) {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        carbon::C_Window::update();
        carbon::C_Events::poll();
    }

    carbon::C_Window::terminate();
    carbon::C_GLWrappper::terminate();

    return 0;
}